/*
 * Copyright 2010 Christian Matzat and others
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package net.matzat.android.hiberdroid.criteria;

public class Projection {
    public enum ProjectionType {
        ROW_COUNT("count(*)"),
        GROUP_PROPERTY(null),
        DISTINCT(null),
        LIMIT(null);

        private String expression;

        private ProjectionType(String expression) {
            this.expression = expression;
        }

        public String getExpression() {
            return expression;
        }
    }

    private ProjectionType projectionType;

    private String property;
    private int limitValue;

    private Projection(ProjectionType projectionType) {
        this(projectionType, null);
    }

    private Projection(ProjectionType projectionType, String property) {
        this.projectionType = projectionType;
        this.property = property;
    }

    private Projection(ProjectionType projectionType, int limitValue) {
        this.projectionType = projectionType;
        this.limitValue = limitValue;
    }

    public static Projection groupProperty(String property) {
        return new Projection(ProjectionType.GROUP_PROPERTY, property);
    }

    public static Projection rowCount() {
        return new Projection(ProjectionType.ROW_COUNT);
    }

    public static Projection distinct() {
        return new Projection(ProjectionType.DISTINCT);
    }

    public static Projection limit(int count) {
        return new Projection(ProjectionType.LIMIT, count);
    }

    public ProjectionType getProjectionType() {
        return projectionType;
    }

    public String getProperty() {
        return property;
    }

    public int getLimitValue() {
        return limitValue;
    }
}
